const Router=require('koa-router');
const talking=new Router();
const sqldata = require('./sqldata');
talking.get('/',async(ctx)=>{
    let mydata = await new Promise((resolve, reject)=>{
        let sql=`select * from user,talking from talking.Uid=user.Uid and talking.Uid='${ctx.request.query.Uid}' and talking.Bid='${ctx.request.Bid}`
        return sqldata(sql, (err, data)=>{
            if(err) reject(err);
            resolve(data);	// 返回拿到的数据
        })
    })
    ctx.body=mydata;
})
talking.post('/',async(ctx)=>{
    let val=ctx.request.body
    let mydata = await new Promise((resolve, reject)=>{
        let sql=`insert into talking values('${val.Uid}','${val.Bid}','${val.Ttime}','${val.Ttext}')`
        return sqldata(sql, (err, data)=>{
            if(err) reject(err);
            resolve(data);	// 返回拿到的数据
        })
    })
    ctx.body=mydata;
})
module.export=talking;
